﻿using System;
using System.Collections.Generic;
using System.Text;
using JUtil.Extensions;

namespace SqlConnectionSettings
{
    public class DalFileExporter
    {
        List<DalFieldInfo> infos = new List<DalFieldInfo>();

        public void Export(string path)
        {
            JUtil.Path.File.Delete(path);

            StringBuilder sb = new StringBuilder();

            foreach (DalFieldInfo info in infos)
            {
                /*
                #region ENAME(CNAME)
                /// <summary>
                /// CNAME
                /// </summary>
                public TYPE ENAME { get; set; }
                #endregion
                 */

                bool CnameIsEqualEname = info.CNAME.Equals(info.ENAME);

                sb.Append(CnameIsEqualEname ? string.Format("#region {0}", info.ENAME) : string.Format("#region {0}({1})", info.ENAME, info.CNAME));
                sb.Append("\n");
                if (!CnameIsEqualEname)
                {
                    sb.Append("/// <summary>");
                    sb.Append("\n");

                    sb.Append(string.Format("/// {0}", info.CNAME));
                    sb.Append("\n");

                    sb.Append("/// </summary>");
                    sb.Append("\n");
                }
                sb.Append("#endregion");
                sb.Append("\n");
            }

            sb.ToString().SaveAs(path);
        }
    }

    public class DalFieldInfo
    {
        private string _ENAME;
        public string ENAME
        {
            get
            {
                return _ENAME.Trim();
            }
            set
            {
                _ENAME = value.Trim();
            }
        }

        private string _CNAME;
        public string CNAME
        {
            get
            {
                return _CNAME.Trim();
            }
            set
            {
                _CNAME = value.Trim();
            }
        }

        Type type;
    }
}
